import 'package:flutter/material.dart';

/// 更新App
class UpdateApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // 返回一个Material Design App页面
    return MaterialApp(
      // 标题
      title: 'Sample App',
      // 主题
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: UpdateAppPage(),
    );
  }
}

/// 示例页
class UpdateAppPage extends StatefulWidget {
  /// 构造方法
  UpdateAppPage({Key key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _UpdateAppPageState();
}

/// SampleAppPage状态类
class _UpdateAppPageState extends State<UpdateAppPage> {
  // 默认占位文字
  String textToShow = "I Like Flutter";

  /// 更新文本
  void _updateText() {
    setState(() {
      textToShow = "Flutter is Awesome!";
    });
  }

  @override
  Widget build(BuildContext context) {
    // 脚手架
    return Scaffold(
      appBar: AppBar(
        // 标题
        title: Text("Sample App"),
      ),
      body: Center(
        child: Text(textToShow),
      ),
      floatingActionButton: FloatingActionButton(
        // 点击所要执行的方法
        onPressed: _updateText,
        // 提示
        tooltip: 'Update Text',
        child: Icon(Icons.update),
      ),
    );
  }
}
